Fix build on MSVC
authorAlex Crichton <alex@alexcrichton.com>
Mon, 15 Jun 2015 05:13:08 +0000 (22:13 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 24 Jun 2015 01:01:32 +0000 (18:01 -0700)
* Download all snapshots and such from static.rust-lang.org (drive-by fix)
* Update dependencies to work and build on MSVC
  * ssh2-sys uses `nmake` to build libssh2
  * libgit2-sys uses `cmake` to build libgit2
  * curl-sys uses `nmake` to build libcurl
  * libz-sys uses `nmake` to build zlib
  * miniz-sys uses `gcc-rs` to drive `cl.exe` manually
  * term updated to pick up windows-specific deps on MSVC
* Updated .travis.install.deps.sh to install MSVC target libraries on Windows,
  so the compiler can be used to target MSVC. A 64-bit target is now used by
  default as well.
* Updated the configure script and Makefile to set appropriate environment
  variables to build Cargo from a MSYS shell with a MSVC target. This is similar
  to how Rust bootstraps on MSVC as well.

With this commit Cargo can successfully bootstrap itself on MSVC (use the MSVC
product to build itself again). The tests currently do not pass because
unwinding is not implemented, but soon!

.travis.install.deps.sh
Cargo.lock
Cargo.toml
Makefile.in
configure
src/etc/dl-snapshot.py

index 0fc51e541e3c22d3c88a9d315e649d0bbb634a65..8e1eb000892b05c02e1e82c71716b860f4753103 100755 (executable)
@@ -20,48 +20,56 @@ if [ "${TRAVIS}" = "true" ] && [ "${target}" = "unknown-linux-gnu" ]; then
     sudo apt-get install g++-multilib lib32stdc++6
 fi
 
-url=https://static-rust-lang-org.s3.amazonaws.com/dist/`cat src/rustversion.txt`
+url=https://static.rust-lang.org/dist/`cat src/rustversion.txt`
 
-# Install both 64 and 32 bit libraries. Apparently travis barfs if you try to
-# just install the right ones? This should enable cross compilation in the
-# future anyway.
+# On unix hosts install both 32 and 64-bit libraries, but respect BITS to
+# determine what arch should be used by default. On windows we don't use 32/64
+# libraries, but instead we install msvc as an alternate architecture.
 if [ -z "${windows}" ]; then
-    rm -rf rustc *.tar.gz
-    curl -O $url/rustc-nightly-i686-$target.tar.gz
-    curl -O $url/rustc-nightly-x86_64-$target.tar.gz
-    tar xfz rustc-nightly-i686-$target.tar.gz
-    tar xfz rustc-nightly-x86_64-$target.tar.gz
-
     if [ "${BITS}" = "32" ]; then
-        src=x86_64
-        dst=i686
+        cargo_extra=x86_64-$target
+        cargo_host=i686-$target
     else
-        src=i686
-        dst=x86_64
+        cargo_extra=i686-$target
+        cargo_host=x86_64-$target
     fi
-    cp -r rustc-nightly-$src-$target/rustc/lib/rustlib/$src-$target \
-          rustc-nightly-$dst-$target/rustc/lib/rustlib
-    (cd rustc-nightly-$dst-$target && \
-     find rustc/lib/rustlib/$src-$target/lib -type f | \
-     sed 's/^rustc\//file:/' >> rustc/manifest.in)
-
-    ./rustc-nightly-$dst-$target/install.sh --prefix=rustc
-    rm -rf rustc-nightly-$src-$target
-    rm -rf rustc-nightly-$dst-$target
-    rm -f rustc-nightly-i686-$target.tar.gz
-    rm -f rustc-nightly-x86_64-$target.tar.gz
+    libdir=lib
 else
-    rm -rf rustc *.exe *.tar.gz
-    if [ "${BITS}" = "64" ]; then
-        triple=x86_64-pc-windows-gnu
+    if [ "${BITS}" = "32" ]; then
+        cargo_host=i686-pc-windows-gnu
+    elif [ "${MSVC}" = "1" ]; then
+        cargo_host=x86_64-pc-windows-msvc
     else
-        triple=i686-pc-windows-gnu
+        cargo_host=x86_64-pc-windows-gnu
+        cargo_extra=x86_64-pc-windows-msvc
     fi
-    curl -O $url/rustc-nightly-$triple.tar.gz
-    tar xfz rustc-nightly-$triple.tar.gz
-    ./rustc-nightly-$triple/install.sh --prefix=rustc
-    rm -rf rustc-nightly-$triple
-    rm -f rustc-nightly-$triple.tar.gz
+    libdir=bin
 fi
 
+rm -rf rustc *.tar.gz
+curl -O $url/rustc-nightly-$cargo_host.tar.gz
+tar xfz rustc-nightly-$cargo_host.tar.gz
+
+if [ ! -z "${cargo_extra}" ]; then
+    curl -O $url/rustc-nightly-$cargo_extra.tar.gz
+    tar xfz rustc-nightly-$cargo_extra.tar.gz
+
+    cp -r rustc-nightly-$cargo_extra/rustc/$libdir/rustlib/$cargo_extra \
+          rustc-nightly-$cargo_host/rustc/$libdir/rustlib
+    cp -r rustc-nightly-$cargo_extra/rustc/$libdir/rustlib/$cargo_extra/bin \
+          rustc-nightly-$cargo_host/rustc/$libdir/rustlib/$cargo_host
+    (cd rustc-nightly-$cargo_host && \
+     find rustc/$libdir/rustlib/$cargo_extra -type f | \
+     sed 's/^rustc\//file:/' >> rustc/manifest.in)
+    (cd rustc-nightly-$cargo_host && \
+     find rustc/$libdir/rustlib/$cargo_host/bin -type f | \
+     sed 's/^rustc\//file:/' >> rustc/manifest.in)
+    rm -rf rustc-nightly-$cargo_extra
+    rm -f rustc-nightly-$cargo_extra.tar.gz
+fi
+
+./rustc-nightly-$cargo_host/install.sh --prefix=rustc
+rm -rf rustc-nightly-$cargo_host
+rm -f rustc-nightly-$cargo_host.tar.gz
+
 set +x
index 6ea192d32b754c892c6c1333041e9e22727e8904..2a0a9a44a9d6237b3ab57b477b2da9e7439546bb 100644 (file)
@@ -15,9 +15,9 @@ dependencies = [
  "hamcrest 0.1.0 (git+https://github.com/carllerche/hamcrest-rust.git)",
  "kernel32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "libgit2-sys 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libgit2-sys 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "num_cpus 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "num_cpus 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "regex 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
  "registry 0.1.0",
  "rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -26,10 +26,10 @@ dependencies = [
  "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "term 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
  "threadpool 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "time 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
+ "time 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
  "toml 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "url 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -37,7 +37,7 @@ name = "advapi32-sys"
 version = "0.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "winapi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -55,7 +55,7 @@ name = "curl"
 version = "0.2.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "curl-sys 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
+ "curl-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -64,11 +64,11 @@ dependencies = [
 
 [[package]]
 name = "curl-sys"
-version = "0.1.22"
+version = "0.1.24"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libz-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -108,7 +108,7 @@ dependencies = [
 
 [[package]]
 name = "gcc"
-version = "0.3.5"
+version = "0.3.8"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
@@ -118,7 +118,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "libgit2-sys 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libgit2-sys 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
  "url 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -148,7 +148,7 @@ name = "kernel32-sys"
 version = "0.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "winapi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -158,12 +158,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "libgit2-sys"
-version = "0.2.14"
+version = "0.2.17"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "libssh2-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)",
- "libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libssh2-sys 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libz-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -178,18 +178,18 @@ dependencies = [
 
 [[package]]
 name = "libssh2-sys"
-version = "0.1.24"
+version = "0.1.25"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libz-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "libz-sys"
-version = "0.1.3"
+version = "0.1.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -214,16 +214,15 @@ name = "miniz-sys"
 version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "gcc 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gcc 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "num_cpus"
-version = "0.1.0"
+version = "0.2.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "gcc 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -232,7 +231,7 @@ name = "openssl-sys"
 version = "0.6.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "gcc 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gcc 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "libressl-pnacl-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -309,7 +308,7 @@ version = "0.2.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "kernel32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -319,10 +318,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "time"
-version = "0.1.25"
+version = "0.1.26"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "gcc 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gcc 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -345,7 +344,7 @@ dependencies = [
 
 [[package]]
 name = "winapi"
-version = "0.1.17"
+version = "0.1.22"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
index 094424d8fdab8fd726df37e552b9d56044f3df9c..65da37271b4a200d3d72456f3d4813f595106c14 100644 (file)
@@ -10,17 +10,20 @@ name = "cargo"
 path = "src/cargo/lib.rs"
 
 [dependencies]
+advapi32-sys = "0.1"
 curl = "0.2"
 docopt = "0.6"
 env_logger = "0.3"
+filetime = "0.1"
 flate2 = "0.2"
 git2 = "0.2"
 git2-curl = "0.2"
 glob = "0.2"
+kernel32-sys = "0.1"
 libc = "0.1"
 libgit2-sys = "0.2"
 log = "0.3"
-num_cpus = "0.1"
+num_cpus = "0.2"
 regex = "0.1"
 registry = { path = "src/registry" }
 rustc-serialize = "0.3"
@@ -31,12 +34,7 @@ threadpool = "0.1"
 time = "0.1"
 toml = "0.1"
 url = "0.2"
-filetime = "0.1"
-
-[target.i686-pc-windows-gnu]
-dependencies = { winapi = "0.1", advapi32-sys = "0.1", kernel32-sys = "0.1" }
-[target.x86_64-pc-windows-gnu]
-dependencies = { winapi = "0.1", advapi32-sys = "0.1", kernel32-sys = "0.1" }
+winapi = "0.1"
 
 [dev-dependencies]
 tempdir = "0.3"
index eb4b33888c703e78cb8b8c78ca801aa958da0b7f..63728b296737b616cf26d6f51220a0beddbe467a 100644 (file)
@@ -53,6 +53,19 @@ BIN_TARGETS := cargo
 BIN_TARGETS := $(BIN_TARGETS:src/bin/%.rs=%)
 BIN_TARGETS := $(filter-out cargo,$(BIN_TARGETS))
 
+ifdef CFG_MSVC_INCLUDE_PATH
+export INCLUDE := $(CFG_MSVC_INCLUDE_PATH)
+endif
+ifdef CFG_MSVC_LIB_PATH
+export LIB := $(CFG_MSVC_LIB_PATH)
+endif
+ifdef CFG_MSVC_BIN
+export PATH := $(CFG_MSVC_BIN):$(PATH)
+endif
+ifdef CFG_MSVC_WINDOWS_SDK_DIR
+export PATH := $(CFG_MSVC_WINDOWS_SDK_DIR):$(PATH)
+endif
+
 define DIST_TARGET
 ifdef CFG_ENABLE_OPTIMIZE
 TARGET_$(1) = $$(TARGET_ROOT)/$(1)/release
index 0ab442f86453de9b98ef813e86d130b7f0fcbd01..a7f9881f2a9ff929c7d217aba98eb6e10dd03763 100755 (executable)
--- a/configure
+++ b/configure
@@ -369,6 +369,52 @@ if [ "$CFG_SRC_DIR" != "$CFG_BUILD_DIR" ]; then
     err "cargo does not currently support an out-of-tree build dir"
 fi
 
+for i in $CFG_TARGET
+do
+    case $i in
+        x86_64-*-msvc)
+            # Use the REG program to figure out where VS is installed
+            # We need to figure out where cl.exe and link.exe are, so we do some
+            # munging and some probing here. We also look for the default
+            # INCLUDE and LIB variables for MSVC so we can set those in the
+            # build system as well.
+            install=$(reg QUERY \
+                       'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\12.0' \
+                       -v InstallDir)
+            need_ok "couldn't find visual studio install root"
+            CFG_MSVC_ROOT=$(echo "$install" | grep InstallDir | sed 's/.*REG_SZ[ ]*//')
+            CFG_MSVC_ROOT=$(dirname "$CFG_MSVC_ROOT")
+            CFG_MSVC_ROOT=$(dirname "$CFG_MSVC_ROOT")
+            CFG_MSVC_BIN="${CFG_MSVC_ROOT}/VC/bin/amd64"
+            CFG_MSVC_CL="${CFG_MSVC_BIN}/cl.exe"
+            CFG_MSVC_LIB="${CFG_MSVC_BIN}/lib.exe"
+            CFG_MSVC_LINK="${CFG_MSVC_BIN}/link.exe"
+
+            vcvarsall="${CFG_MSVC_ROOT}/VC/vcvarsall.bat"
+            CFG_MSVC_INCLUDE_PATH=$(cmd /c "\"$vcvarsall\" amd64 && cmd /c echo %INCLUDE%")
+            need_ok "failed to learn about MSVC's INCLUDE"
+            CFG_MSVC_LIB_PATH=$(cmd /c "\"$vcvarsall\" amd64 && cmd /c echo %LIB%")
+            need_ok "failed to learn about MSVC's LIB"
+            CFG_MSVC_WINDOWS_SDK_DIR=$(cmd /c \
+                "\"$vcvarsall\" amd64 && cmd /c echo %WindowsSdkDir%")
+            need_ok "failed to learn about MSVC's WindowsSdkDir"
+            export CFG_MSVC_WINDOWS_SDK_DIR="${CFG_MSVC_WINDOWS_SDK_DIR}bin/x64"
+
+            putvar CFG_MSVC_ROOT
+            putvar CFG_MSVC_BIN
+            putvar CFG_MSVC_CL
+            putvar CFG_MSVC_LIB
+            putvar CFG_MSVC_LINK
+            putvar CFG_MSVC_INCLUDE_PATH
+            putvar CFG_MSVC_LIB_PATH
+            putvar CFG_MSVC_WINDOWS_SDK_DIR
+            ;;
+
+        *)
+            ;;
+    esac
+done
+
 if [ ! -z "$CFG_ENABLE_NIGHTLY" ]; then
     if [ ! -f .cargo/config ]; then
         mkdir -p .cargo
index 97e394fa37387eaf28a9a3ec56f75b2914a3f60f..a7f8c19070840d12813f0dc7dca1c5d4079c2f06 100644 (file)
@@ -72,7 +72,7 @@ triple = "%s-%s-%s" % (arch, vendor, target_os)
 hash = snaps[date][platform]
 
 tarball = 'cargo-nightly-' + triple + '.tar.gz'
-url = 'https://static-rust-lang-org.s3.amazonaws.com/cargo-dist/%s/%s' % \
+url = 'https://static.rust-lang.org/cargo-dist/%s/%s' % \
   (date.strip(), tarball)
 dl_path = "target/dl/" + tarball
 dst = "target/snapshot"